//
//  MathSDKTests.m
//  MathSDKTests
//
//  Created by admin on 16/7/5.
//  Copyright © 2016年 douyu. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "Vector3.h"
#import <math.h>

@interface Vector3Tests : XCTestCase

@end

@implementation Vector3Tests

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testIsVectorEqual
{
    Vector3 vec1 = {0.f, 0.f, 0.f};
    Vector3 vec2 = {1.f, 2.f, 3.f};
    Vector3 vec3 = {2.f, 3.f, 4.f};
    Vector3 vec4 = {2.f, 3.f, 4.f};
    
    XCTAssert(isVectorEqual(vec1, kVector3Zero) == true);
    XCTAssert(isVectorEqual(vec2, vec3) == false);
    XCTAssert(isVectorEqual(vec3, vec4) == true);
}

- (void)testPlusNum
{
    Vector3 vec1 = {0.f, 0.f, 0.f};
    Vector3 vec2 = {1.f, 2.f, 3.f};
    
    float plusNumber1 = 2.f;
    float plusNumber2 = 3.f;
    
    Vector3 result1 = {2.f, 2.f, 2.f};
    Vector3 result2 = {4.f, 5.f, 6.f};
    
    
    XCTAssert(isVectorEqual(plusNum(vec1, plusNumber1), result1));
    XCTAssert(isVectorEqual(plusNum(vec2, plusNumber2), result2));
}

- (void)testModulo
{
    float number = modulo((Vector3){5.f, -4.f, 7.f});
    float result = sqrtf(90.f);
    XCTAssert(number == result);
}

- (void)testMultiplyNum
{
    Vector3 vec1 = {1.f, 2.f, 3.f};
    Vector3 vec2 = {-5.f, 0.f, 0.4f};
    Vector3 vec3 = {4.7f, -6.f, 8.f};
    
    float number1 = 2.f;
    float number2 = -3.f;
    float number3 = 1/2.f;
    
    Vector3 result1 = {2.f, 4.f, 6.f};
    Vector3 result2 = {15.f, 0.f, -1.2f};
    Vector3 result3 = {2.35f, -3.f, 4.f};
    
    XCTAssert(isVectorEqual(result1, multiplyNum(vec1, number1)));
    XCTAssert(isVectorEqual(result2, multiplyNum(vec2, number2)));
    XCTAssert(isVectorEqual(result3, multiplyNum(vec3, number3)));
}

- (void)testNormalize
{
    Vector3 vec = {12.f, -5.f, 0.f};
    Vector3 result = {0.923076987f, -0.384615391, 0};
    
    Vector3 test = normalize(vec);
    XCTAssert(isVectorEqual(test, result));
}

- (void)testPlus
{
    Vector3 vec1 = {1.f, 2.f, 3.f};
    Vector3 vec2 = {4.f, 5.f, 6.f};
    
    Vector3 result = {5.f, 7.f, 9.f};
    
    XCTAssert(isVectorEqual(plus(vec1, vec2), result));
}

- (void)testMinus
{
    Vector3 vec1 = {1.f, 2.f, 3.f};
    Vector3 vec2 = {4.f, 5.f, 6.f};
    
    Vector3 result = {-3.f, -3.f, -3.f};
    
    XCTAssert(isVectorEqual(minus(vec1, vec2), result));
}

- (void)testDistance
{
    Vector3 vec1 = {5.f, 0.f};
    Vector3 vec2 = {-1.f, 8.f};
    
    XCTAssert(distance(vec1, vec2) == 10);
}

- (void)testDotProduct
{
    Vector3 vec1 = {3.f, -2.f, 7.f};
    Vector3 vec2 = {0.f, 4.f, -1.f};
    
    XCTAssert(dotProduct(vec1, vec2) == -15);
}

- (void)testCrossProduct
{
    Vector3 vec1 = {1.f, 3.f, 4.f};
    Vector3 vec2 = {2.f, -5.f, 8.f};
    
    Vector3 result = {44.f, 0.f, -11.f};

    XCTAssert(isVectorEqual(crossProduct(vec1, vec2), result));
}

/*
- (void)testPerformanceExample {
    // This is an example of a performance test case.
    [self measureBlock:^{
        // Put the code you want to measure the time of here.
    }];
}
 */

@end
